home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / PASCAL / ALLSWAGS.ZIP / SWAGN-R.ZIP / NETWORK.SWG / 0029_IPX Packet Transfer.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-05-26  |  4.0 KB  |  131 lines

  1. {
  2.      A while back I posted a unit which allows one to interrface Pascal
  3. programs to IPX.  Since I've had several people ask about how to use it,
  4. I'll post this short example program now.  It should be enough to get
  5. anyone started on sending packets.
  6.      NOTE:  You must already have the IPX.PAS unit posted earlier in
  7. this conference in order to use this program.  Also, this program uses
  8. two NetWare functions to get the address of the remote user, so both
  9. users must be logged in on the same server (but don't have to be on the
  10. same network) to get the program to work.  The title of the program is
  11. TALK.PAS.  In order to run the program you type TALK <username> from the
  12. command line.
  13.  
  14. From: greg.miller@shivasys.com
  15.  
  16.  This program sends packets between two users logged in
  17.  to the same server.  This program is meant to be an example
  18.  of how to send IPX packets over an IPX network and is not
  19.  meant to be an actual utility.
  20. }
  21. program send;
  22. uses crt,ipx;
  23.  
  24. const
  25.  receive_socket = $7777; {Arbitrary socket numbers are chosen}
  26.  send_socket = $6666;
  27.  
  28. procedure abort(message:string);
  29. begin
  30.  writeln(message);
  31.  halt(1);
  32. end;
  33.  
  34. var
  35.  connection_number:word;
  36.  network_number:networkNumber;
  37.  network_node:networkNode;
  38.  receive_ecb,send_ecb:ECB;
  39.  receive_header,send_header:IPXHeader;
  40.  receive_message,send_message:MessageSTR;
  41.  done,stop : boolean;
  42.  
  43.  begin
  44.   {Make sure IPX is installed, otherwise don't continue}
  45.   if not IPXinstalled then abort('IPX not loaded');
  46.  
  47.   {Get the username from the command line, and use it to get the users
  48.    connection number}
  49.   connection_number := Get1stConnectionNumber(paramstr(1));
  50.   {0 is returned, if the user isn't logged in}
  51.   if connection_number = 0 then abort(paramstr(1) + ' not found. ');
  52.  
  53.   {Use the connection number obtained from above to get the users 
  54. address}
  55.   if GetINternetAddress(connection_number,network_number,network_node) 
  56. <> 0
  57.       then abort(paramstr(1) + 'network error.');
  58.  
  59.   {Initialize IPX sockets for communication}
  60.   IpxCloseSocket(send_socket);
  61.   if IPXOpenSocket(send_socket) <> 0 then abort('Socket error.');
  62.   IPXCloseSocket(receive_socket);
  63.   if IPXOpenSocket(receive_socket) <> 0 then abort('Socket error.');
  64.  
  65. {The chat program}
  66. stop := false;
  67. writeln('Attempting to enter chat (^ to stop)');
  68. while (receive_message <> 'ack') and (not stop) do
  69.  begin
  70.   if keypressed then
  71.    if readkey = '^' then stop := true;
  72.   send_message := 'ack';
  73.   IPXSend(network_number,
  74.           network_node,
  75.           receive_socket,
  76.           @send_message,
  77.           length(send_message)+1,
  78.           send_ecb,
  79.           send_header,
  80.           send_socket);
  81.  
  82.   IPXReceive(receive_ecb, receive_header, receive_socket,
  83.              @receive_message, sizeof(receive_message));
  84.  end;
  85.  
  86. if stop = true then
  87.  else
  88.   begin
  89.   writeln('Entering Chat mode: type ^ to exit');
  90.   done := false;
  91.   repeat
  92.    if (receive_ecb.completion_code = 0) and (receive_ecb.in_use = 0)
  93.         then
  94.          begin
  95.           textcolor(lightgreen);
  96.           write(receive_message);
  97.           if receive_message=chr(13) then writeln;
  98.           IPXReceive(receive_ecb, receive_header, receive_socket,
  99.           @receive_message, sizeof(receive_message));
  100.          end;
  101.  
  102.    IPXRelinquishControl; {This line allows IPX to do computation}
  103.    if KeyPressed
  104.     then
  105.      begin
  106.       send_message := '';
  107.       send_message := ReadKey;
  108.       textcolor(yellow);
  109.       write(send_message);
  110.       if send_message=chr(13) then writeln;
  111.       IPXSend(network_number,
  112.               network_node,
  113.               receive_socket,
  114.               @send_message,
  115.               length(send_message)+1,
  116.               send_ecb,
  117.               send_header,
  118.               send_socket);
  119.      end;
  120.    if (send_message = '^') or (receive_message= '^') then
  121.     begin
  122.      writeln('Exiting Chat mode');
  123.      done := true;
  124.      IPXCloseSocket(send_socket);
  125.      IPXCloseSocket(receive_socket);
  126.     end;
  127.   until done;
  128.  end;
  129.  end.
  130.  
  131.